<template>
  <el-dialog
    class="erEditorShow"
    title="修改二衬检测报告"
    :visible.sync="dialogEditorVisible"
    width="50%"
    :before-close="handleClose"
  >
    <el-form
      :inline="true"
      ref="form"
      :model="currentRow"
      label-width="150px"
      class="demo-form-inline"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="开始里程">
            <el-input v-model="currentRow.startMileage"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结束里程">
            <el-input v-model="currentRow.endMileage"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="检测长度">
            <el-input v-model="currentRow.mileageLength"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="检测内容">
            <el-input v-model="currentRow.mileageContext"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="检测结果">
            <el-radio v-model="currentRow.result"  label="1">合格</el-radio>
            <el-radio v-model="currentRow.result"  label="2">不合格</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="创建时间">
            <el-date-picker
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期"
              v-model="currentRow.createTime"
              style="width: 100%;"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="二衬背后空洞">
            <el-input v-model="currentRow.erHollow"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="二衬厚度">
            <el-input v-model="currentRow.erThickness"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="报告">
            <el-upload
              name="file"
              class="upload-demo"
              action="string"
              :http-request="beforeAvatarUploadThree"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :limit="3"
              :on-success="handlesuccess"
              :on-error="handleerror"
              :on-exceed="handleExceed"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogEditorVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from "../../../api";
import qs from "qs";

export default {
  data() {
    return {
      dialogEditorVisible: false,
      tunnelList: [],
      fileList: [],
      currentRow: {},
      pageNo:1
    };
  },
  mounted() {
    this.$bus.$on("onShowerEditor", (row) => {
      this.dialogEditorVisible = true;
      this.currentRow = row.rowdata;
      this.wId = row.wId;
      this.pageNo = row.pageNo
    });
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    create() {
      api
        .monitorMeasureupdate(qs.stringify(this.currentRow))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: "success",
              message: "更新成功!",
            });
            this.dialogEditorVisible = false;
            this.$bus.$emit("onerRefresher", {pageNo:this.pageNo,wId:this.currentRow.wId});
          }
        })
        .catch((err) => {});
    },
    onSubmit() {
      console.log("submit!");
    },
    handlesuccess(response, file, fileList) {
      console.log(response);
      if (response.code == 2001) {
        this.currentRow.resources = response.data;
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleerror(err, file, fileList) {
      console.log(err);
    },
    beforeAvatarUploadThree(file) {
      let params = new FormData();
      params.append("file", file.file);
      api
        .AddrPlaneFileUpload(params)
        .then((res) => {
          if (res.data.code == 2001) {
            this.form.resources = res.data.data;
          }
        })
        .catch((err) => {});
    },
  },
};
</script>

<style scoped>
.avatar-uploader .el-upload {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  width: 50px !important;
  height: 50px !important;
  font-size: 28px;
  line-height: 50px !important;
  color: #8c939d;
  text-align: center;
}
.avatar {
  display: block;
  width: 50px !important;
  height: 50px !important;
}
.imgbeforepad {
  padding-top: 0px !important;
}
.avatar-uploader .el-icon-plus {
  margin: 15px !important;
}
.erEditorShow :deep(.el-input--suffix .el-input__inner) {
  width: 202px;
}
.erEditorShow :deep(.el-textarea__inner) {
  width: 202px;
}
.erEditorShow :deep(.el-form--inline .el-form-item__content) {
  width: 202px;
}
</style>